<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
require_once  '../classes/ConnectionDB.php';
require_once  '../classes/UtenteManager.php';
require_once  '../classes/TestDataManager.php';
require_once  '../bean/Argomento.php';
$connection =ConnectionDB::getInstance()->connectToDB();
$codiceUtente = $_COOKIE['codiceUtente'];
$result = UtenteManager::getInstance()->getUtente($connection, $codiceUtente);

$argomenti =TestDataManager::getInstance()->getArgomenti($connection, $codiceUtente);


?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Report domande</title>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/prototype.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/scriptaculous/effects.js" type="text/javascript"></script>
        <script src="../glassboxLatest/glassbox.2.0.0/javascripts/glassbox/glassbox.js" type="text/javascript"></script>
        <style type="text/css">
            @import url("../css/style.css");
            table{
                width: 100%;
            }

            #tableResults td{
                text-align: center;
            }


            #searchForm {
                padding-top: 3%;
                margin-left: -5px;
            }

            #searchFormCont
            {
                padding-left: 2%;
            }

           

        </style>
        <script type="text/javascript">
            path_to_root_dir = "../glassboxLatest/glassbox.2.0.0/";
            var listaDomande;
            var numItem=8;
            var currentIndex=0;

            window.onload = function()
            {
                var searchForm = new GlassBox();
                searchForm.init( 'searchForm', '640px', '190px', 'hidden','',true, false);
                searchForm.ipos();
                searchForm.appear();

                var results = new GlassBox();
                results.init( 'results', '1040px', '460px', '','',true,false);
                results.ipos();
                results.appear();
            }

            function xXMLHttpRequest()
            {

                var client = null;
                if (window.XMLHttpRequest)
                {
                    client=new XMLHttpRequest();
                }
                // code for IE
                else if (window.ActiveXObject)
                {
                    client=new ActiveXObject("Microsoft.XMLHTTP");
                }

                return client;
            }

            function handler() {
                if(this.readyState == 4 && this.status == 200)
                {
                           alert("resp : " + this.responseText);
                    var resp = eval(this.responseText);
                    listaDomande = new Array();
                    for(i=0;i<resp.length; i++)
                    {
                        listaDomande[i] = resp[i];
                    }

                    manageNavi(0);




                } else if (this.readyState == 4 && this.status != 200) {
                    // fetched the wrong page or network error...
                    alert("error this.status : " + this.status );

                }
            }

            function find()
            {
                var client = xXMLHttpRequest();
                client.onreadystatechange = handler;
                var codiceArgomento = document.getElementById('codiceArgomento').value;
                var tipologia = document.getElementById('tipologia').value;
                var domandaLike =document.getElementById('domandaLike').value;

                var param = "codiceArgomento="+ codiceArgomento +
                    "&tipologia="+tipologia+
                    "&domandaLike="+domandaLike;
                client.open("POST", "reportQuestionsListenerJson.php", true);
                client.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

                client.send(param);

            }

            function manageNavi(ind)
            {
                var tmp= new Array();

                var str="<table id='tableResults' cellpadding='5' border='1'>"
                    +"<tr>"
                    +"<th>Codice domanda</th>"
                    +"<th>Domanda</th>"
                    +"<th>Argomento</th>"
                    +"<th>Tipologia</th>"
                    +"<th>Dettaglio</th>"
                    +"</tr>";
                var indCurrenct=0;
                while(indCurrenct<numItem)
                {
                    //                    alert("idn " + ind);
                    if(ind<listaDomande.length)
                    {
                        tmp=listaDomande[ind];
                        var nomeTipologia;
                        if(tmp.tipologia=='1')
                            nomeTipologia="Vero/Falso";
                        else
                            nomeTipologia="Risposta multipla";
                        str+="<tr><td>"+tmp.codiceDomanda+"</td>"+
                            "<td>"+tmp.testoDomanda+"</td>"+
                            "<td>"+tmp.nomeArgomento+"</td>"+
                            "<td>"+nomeTipologia+"</td>"+
                            "<td><a href='detailQuestion.php?codiceDomanda="+tmp.codiceDomanda+"'><img src='../images/icons/PNG/Preview Docment.png' height='30' width='30' title='Dettaglio domanda' border='0' /></a></td></tr>";
                    }
                    ind++;
                    indCurrenct++;
                }
                str +="</table>";
                var numTotItem = listaDomande.length;
                var numPag = Math.ceil(numTotItem / numItem);
                if(numPag > 1)
                {
                    str +="<div id='navigator'><center>";
                    var current = 0;
                    var toPrint=1
                    for(k=1;k<=numPag;k++)
                    {
                        str+="<a href='javascript:manageNavi("+current+")'>"+toPrint+"</a>&nbsp;&nbsp;";
                        current= k * numItem;
                        toPrint = toPrint+1;
                    }
                    str+="</center></div>";
                }
                document.getElementById('resultsCont').innerHTML=str;
            }

            function showDetail(codice)
            {
                location.href="detailQuestion.php?codiceDomanda=" + codice;
            }
        </script>
    </head>
    <body>

        <?php include '../portal/header.php';?>
        <center>
            <div id="searchForm">
                <div id="searchFormCont">
                    <table>
                        <tr>
                            <th>Ricerca Domande</th>
                        </tr>
                        <tr>
                            <td>Argomento:</td>
                            <td><select name="codiceArgomento" id="codiceArgomento">
                                    <option value="">Tutti</option>
                                    <?
                                    for($j=0; $j<count($argomenti); $j++)
                                    {?>
                                    <option value="<?= $argomenti[$j]->getCodice() ?>"><?= $argomenti[$j]->getNome() ?></option>
                                        <? }?>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>Tipologia</td>
                            <td>
                                <select name="tipologia" id="tipologia">
                                    <option value="">Tutte</option>
                                    <option value="1">Vero / Falso</option>
                                    <option value="2">Risposta multipla</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>Domanda contiene:</td>
                            <td><input type="text" name="domandaLike" id="domandaLike" /></td>
                        </tr>

                        <tr>
                            <td colspan="2">&nbsp;</td>
                            <td>
                                <input type="button" value="Cerca" onclick="find();" />
                            </td>
                        </tr>


                    </table>
                </div>
            </div>
            <div id="results"><div id="resultsCont"></div></div>
        </center>
    </body>
</html>
